var EventEmitter = require('events').EventEmitter

var life  = new EventEmitter()
life.setMaxListeners(11)//默认为每个事件最大添加十个监听

//addEventListener

function listener1 (who) {
	console.log('给'+who+'1')
}

life.on('求安慰',listener1)

life.on('求安慰',function(who){
	console.log('给'+who+'2')
})

life.on('求安慰',function(who){
	console.log('给'+who+'3')
})

life.on('求安慰',function(who){
	console.log('给'+who+'4')
})

life.on('求安慰',function(who){
	console.log('给'+who+'5')
})

life.on('求安慰',function(who){
	console.log('给'+who+'6')
})

life.on('求安慰',function(who){
	console.log('给'+who+'7')
})

life.on('求安慰',function(who){
	console.log('给'+who+'8')
})

life.on('求安慰',function(who){
	console.log('给'+who+'9')
})

life.on('求安慰',function(who){
	console.log('给'+who+'10')
})

life.on('求安慰',function(who){
	console.log('给'+who+'11')
})

life.on("求你爱",function(who){

})

//不可取，因为匿名函数相当于新生成的对象，所以移除的不是对应的函数
/*life.removeListener('求安慰',function(who){
	console.log('给'+who+'1')
})*/
life.removeListener('求安慰',listener1)
life.removeAllListeners('求安慰')

var hasComfortListener = life.emit('求安慰','汉子')
var hasLovedListener = life.emit('求你爱','妹子')

console.log(life.listeners('求安慰').length)
console.log(life.listeners('求你爱').length)
//console.log(EventEmitter.listenerCount(life,'求安慰'))

/*var hasPlayedListener = life.emit('求玩坏','汉子和妹子')

console.log(hasComfortListener)
console.log(hasLovedListener)
console.log(hasPlayedListener)*/





